<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<%@include file="/views/common/include/taglib.jsp"%>
<%@include file="/views/common/include/head.jsp"%>
<title>Insert title here</title>
<script type="text/javascript">
$(function(){
	var ctx = '${ctx}';
	var url = '${ctx}' + '/shopcart/payCode?orderNumber=' + $('#orderNumber').val();
	$('#QRCode').attr('src', url);
	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	
	var payResult = false;
	window.setInterval(function(){ 
		checkResult(); 
	}, 3000); 
	
	var doing = false;
	function checkResult(){
		if(!doing){
			doing = true;
			$.ajax({
	            type : "GET",
	            url : ctx + "/shopcart/wxPayResult?orderNumber="+$('#orderNumber').val(),
	            cache : false,
	            dataType : 'json',
	            success : function(data) {
	                if (data.success) {
	                    alert('支付成功');
	                    window.parent.setPayStatus(true);
	                    parent.layer.close(index);
	                } else {
	                   // alert(data.msg);
	                }
	                doing = false;
	            }
	        });
		}
	}
	$('#resultBtn').click(function (){
		$.ajax({
	        type : "GET",
	        url : ctx + "/shopcart/wxPayResult?orderNumber="+$('#orderNumber').val(),
	        cache : false,
	        dataType : 'json',
	        success : function(data) {
	            if (data.success) {
	                layer.msg("支付成功", {
	                    icon : 1,
	                    time : 2000
	                });
	                window.parent.setPayStatus(true);
	                parent.layer.close(index);
	            } else {
	            	alert(data.msg);
	            }
	        }
	    });
	});
});
</script>
</head>
<body style=" margin: 0px; text-align: center;">
<input type="hidden" value="<%=request.getParameter("orderNumber")%>" id="orderNumber"/>
<div style="">
    <img id="QRCode"  width="174px">
</div>
<div style="">
    <img id=""  src="${ctx}/images/qrdd/paytip.png">
</div>
<!-- <input type="button" id="resultBtn" value="查看支付结果"/> -->
</body>
</html>